home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ9205.ARJ / README < prev    next >
Text File  |  1992-04-04  |  14KB  |  282 lines

  1. This is the source for the X-Sharp 3-D animation package, version 18, as
  2. presented in the Graphics Programming column in Dr. Dobb's Journal,
  3. as of the July 1992 issue.  Illumination, a color model, and 8088/286
  4. support have been added since the last version, version 15a.  The code
  5. has been tested with Borland C++ 3.0 and TASM 3.0.  To make the X-Sharp
  6. demo program DEMO1, run K1.BAT.  When you run DEMO1, I suggest you use the
  7. '0' key to turn on a spotlight, then use the 'T' key to move the ball up
  8. close to the screen, then use the arrow keys to move the ball around; it's
  9. a pretty neat sight!
  10.  
  11. Unpack this archive with PKUNZIP -d; the ball generation code belongs
  12. in the .\BALL subdirectory, and, because it has some of the same
  13. filenames as the main directory, problems will result without -d.
  14.  
  15. Files in this archive:
  16.  
  17. APPROT.C     - appends rotations in X, Y, and Z
  18. BALL         - subdirectory containing ball-generation code; see below
  19. BALVERT0.INC - include file generated by .\BALL\GENBALL that defines
  20.                 ball-shaped object
  21. COLOR.C      - RGB space -> adapter palette space color mapping, color
  22.                intensity adjustment
  23. COSTABLE.INC - include file for fixed-point cosines between 0 and 90 degrees,
  24.                 generated by GENCOS
  25. DEMO1.C      - X-Sharp demo program
  26. DRAW.ASM     - draws the scanned-out pixels of a convex polygon in mode X
  27. DRAWPOBJ.C   - draws a polygon-based object
  28. FILLCNVX.C   - fills a convex polygon
  29. FILLRECT.ASM - fills a rectangle with a solid color in mode X
  30. FIXED.ASM    - fixed point arithmetic routines
  31. GAMMA        - subdirectory containing gamma correction table generation
  32.                 program
  33. GENCOS.C     - generates cosine table for fixed-point look-up
  34. GLOBALS.C    - global variables
  35. INITBALL.C   - initializes the ball-shaped object
  36. INITFIX.C    - initializes fixed-point data
  37. INITLIGH.C   - sets up initial illumination (ambient and diffuse lighting)
  38. INITPAL.C    - sets up the adapter color palette
  39. K1.BAT       - remakes X-Sharp, producing demo program DEMO1
  40. LIGHTING.C   - illumination control
  41. LINKRESP     - TLINK response file
  42. MAKEFILE     - Borland Make makefile
  43. MODE.ASM     - initializes the screen to mode X (320x240, 256 colors)
  44. MOVEOBJ.C    - updates the position and orientation of polygon-based objects
  45. OLIST.C      - object list initialization, handling, and sorting
  46. POLYGON.H    - polygon & 3-D header file
  47. README       - this file
  48. SCAN.ASM     - scans out an edge of a convex polygon
  49. SHOWPAGE.ASM - selects the video page that's visible
  50. TURBOC.CFG   - Borland C++ 3.0 configuration file.  Uses 3.0-specific
  51.                 options, which must be changed for 2.0 and earlier
  52. XFPROJ.C     - transforms and projects polygon-based objects
  53. XSHARP18     - ID file for the X-Sharp version
  54. XSHARP.C     - main() for this animation
  55.  
  56. The subdirectory .\BALL contains the source code and executable for
  57. the program GENBALL, which creates the vertex and face lists for a
  58. ball made from rectangular faces (BALVERT0.INC was created by GENBALL).
  59. Remake GENBALL by running K.BAT in the .\BALL directory.  See the
  60. 12/29/91 log entry for details.
  61.  
  62. Note that this code uses 386-specific instructions unless USE386 is
  63. set to 0 in FIXED.ASM.  With USE386 set to 0, the demo will run on an 8088
  64. or 286, but performance is poor except on a very fast 286.  Performance is
  65. quite good on a 20 MHz 386, and very good--30 to 60 frames per second--on
  66. a 33 MHz 486.
  67.  
  68. In case you're curious, yes, I am planning on splitting this into adapter
  69. specific driver code, X-Sharp core code, and application code in the near
  70. future.  It's not going to stay in one big mass of code forever!
  71.  
  72. Comments and questions may be directed to me in the following ways:
  73.  
  74. Bix: graphic.disp or graphic.pgms conferences or Bixmail (mabrash)
  75. MCI mail (mabrash)
  76. M&T Online programming.graphics conference (mabrash)
  77. U.S. Mail (7 Adirondack Street, South Burlington, VT 05403)
  78.  
  79. Bix is the best way to get hold of me.
  80.  
  81. This material may be used freely; it is provided free of charge, as
  82. are responses to questions and comments, within reason.  Should the
  83. spirit move you, a contribution to the Vermont Assocation for the
  84. Blind and Visually Impaired, sent care of Dr. Dobb's Journal, myself,
  85. or directly to VABVI, would be appreciated, and would motivate me to
  86. keep enhancing X-Sharp.
  87.  
  88. Vermont Association for the Blind and Visually Impaired
  89. 37 Elmwood Avenue
  90. Burlington, VT 05401
  91.  
  92. Dr. Dobb's Journal
  93. 411 Borel Avenue, Suite 100
  94. San Mateo, CA 94403-3522
  95.  
  96. *****************************************************************
  97. * This code is provided as-is, with no warranties of any sort.  *
  98. * So far as I know, it works fine, but use it at your own risk! *
  99. *****************************************************************
  100.  
  101. --Michael Abrash  4/3/92
  102.  
  103.  
  104.                      ******************
  105.                      * Log of changes *
  106.                      ******************
  107.  
  108. **********************************************************************
  109. Begin entry for 4/3/92
  110.  
  111. ----------
  112. Implemented support for 8088 and 286 fixed-point math in FIXED.ASM.
  113. Previously, only 386 and up processors were supported.  See comments in
  114. FIXED.ASM for limitations of the 8088/286 version of FixedDiv().
  115.  
  116. ----------
  117. Altered the polygon Face structure so that the first vertex in the vertex
  118. list (VertNums) for any shaded polygon must now be the endpoint of a unit
  119. normal vector that has the second vertex in the vertex list as the
  120. startpoint. This unit vector is then transformed along with the rest of the
  121. polygon, and is used for calculating diffuse shading.  Note that the first
  122. vertex in the polygon's vertex list is *not* a vertex of the actual polygon,
  123. just the endpoint of the unit normal.  However, the second vertex in the
  124. polygon's vertex list *is* a vertex of the actual polygon.  Look at
  125. GENBALL.C, in subdirectory BALL, to see an example of the creation of
  126. polygon vertices and face lists.  Note that NumVerts in the polygon
  127. Face structure does not count the first (unit-normal endpoint) vertex.
  128.  
  129. Changed XFPROJ.C so that unit normal endpoints are only transformed into
  130. view space, not into screen space or screen coordinates.  Since the unit
  131. normals are useless once they're transformed into screen space (they're not
  132. normals at that point, because perspective transformation doesn't preserve
  133. angles), there's no reason to waste time transforming them into screen space,
  134. so we don't.  This requires that the unit normal endpoints *always* be the
  135. last endpoints in an object's vertex list, and that NumRealVerts (a new entry
  136. in the PObject structure) now specifies how many real polgyon vertices there
  137. are (that is, how many vertices there are excluding unit normal endpoints),
  138. so that XFPROJ.C knows to only transform NumRealVerts vertices into screen
  139. space.
  140.  
  141. ----------
  142. Implemented a full-color color model.  Polygon colors are now described as
  143. RGB triples, with 8 bits of resolution for each color component.  These
  144. colors are stored in ModelColor structures.  There is a ModelColor entry
  145. in each polygon's Face structure.  There is also a ColorIndex entry,
  146. specifying a direct color index to be used for drawing the polygon; this is
  147. equivalent to the previous style of drawing polygons, and is used only for
  148. unshaded (unilluminated) polygons.  Of course, the VGA doesn't have 24 bits
  149. per pixel.  InitializePalette(), in INITPAL.C, sets up the palette however
  150. you'd like; currently with 64 levels each of pure red, green, and blue, and
  151. 2 levels each of red, green, and blue for mixing.  This is a good model for
  152. displaying pure primary colors, but suffers severe color quantization for
  153. mixed colors.  ModelColorToColorIndex(), in COLOR.C, maps colors from the
  154. model 24-bit RGB color space into the actual available palette.  Note that
  155. InitializePalette() and ModelColorToColorIndex() are designed as replaceable
  156. modules, so any desired adapter-specific color mapping can easily be
  157. implemented; the rest of X-Sharp works in 24-bit RGB space.
  158.  
  159. ----------
  160. Implemented two types of shading:  ambient and diffuse (Lambert).  Ambient
  161. shading is nondirectional illumination, basically background light.
  162. Diffuse shading is directed illumination, treated as illumination by
  163. infinitely distant spotlights in X-Sharp and defined by a unit vector for
  164. direction and an RGB intensity for illumination level.  Added the ShadingType
  165. field to the polygon Face structure to select either, both, or neither of
  166. AMBIENT_SHADING and DIFFUSE_SHADING.  Modified DRAWPOBJ.C to perform the
  167. selected shading, using the unit normal of each polygon (discussed above),
  168. the RGB color of the polygon, the unit vector of each spotlight, and the
  169. intensity of each spotlight to calculate the shading for each polygon.
  170. Created the ModelIntensity structure to describe ambient and spotlight
  171. intensity levels as fixed-point RGB values.  Added a variety of functions
  172. to control illumination in LIGHTING.C.  Added InitializeLighting() to set
  173. up the initial lighting state.
  174.  
  175. ----------
  176. Implemented main program DEMO1.C, which displays a shaded, faceted ball with
  177. ambient lighting and three user-controllable spotlights, as well as
  178. user-controllable positioning, as the current X-Sharp demo program.  This
  179. replaces the previous demo program XS.C.
  180.  
  181. ----------
  182. Modified INITBALL.C to support the new polygon format, new color model, and
  183. shading.  The ball now has 71 faces that are illuminated with both diffuse
  184. and ambient shading, and 1 unshaded face that always has a constant color,
  185. yellow.
  186.  
  187. ----------
  188. Eliminated INITCUBE.C.
  189.  
  190. ----------
  191. Renamed MOVEPOLY.C to MOVEOBJ.C and changed function RotateAndMovePObject()
  192. to handle movement events set in main() and renamed the function to
  193. RotateAndMoveBall().
  194.  
  195. ----------
  196. Modified .\BALL\GENBALL.C to generate the new polygon format, with the
  197. first vertex for each face now the endpoint of a unit normal coming out of
  198. the second vertex.  The first vertex is not a part of the polygon, but is
  199. only used to determine the polygon's orientation.  See the above entry on
  200. the polygon Face structure for details.
  201.  
  202. ----------
  203. Other, minor changes such as the addition of some macros have been made.  I'm
  204. afraid I don't remember 'em all...
  205.  
  206. End entry for 4/3/92
  207. **********************************************************************
  208. Begin entry for 1/5/92
  209.  
  210. ----------
  211. Altered ConcatXforms to add in the translation element from matrix #1
  212. only when multiplying by the fourth column of matrix #2, because only
  213. the fourth column has a 1 at the bottom.  This fixes a bug in earlier
  214. versions that showed up when a world->view transformation involving
  215. translation was used.
  216.  
  217. ----------
  218. Removed setting of non-existent element XformToWorld[3][3] in INITCUBE.C
  219. and INITBALL.C.
  220.  
  221. End entry for 1/5/92
  222. **********************************************************************
  223. Begin entry for 12/29/91
  224.  
  225. ----------
  226. Converted XformVec and ConcatXforms to assembly language, reducing
  227. transformation and concatenation time to 5% or less of total time.
  228.  
  229. ----------
  230. Converted sin() and cos() calls to calls to the assembly language
  231. function CosSin(), which performs a table look-up.  Changed angle
  232. representations from radians to tenths of degrees to facilitate table
  233. look-up and to maximize accuracy.
  234.  
  235. ----------
  236. Put all the assembly language functions in fixed.asm, replacing
  237. l4.c and l9.asm.
  238.  
  239. ----------
  240. Deleted one cube from the animation, and substituted a ball.  The
  241. ball has a radius of 25, slightly larger than the cube it replaces.
  242. It has 6 bands of 12 facets each, for a total of 72 faces,
  243. approximately doubling the number of polygons in the animation, and
  244. has 62 vertices, increasing the number of vertices by more than 50%.
  245. Added INITBALL.C to initialize the ball, and added a call to
  246. InitializeBalls() to create the ball in main().  Only one ball is
  247. created, but more balls could easily be added, and the size of and
  248. number of bands in the ball(s) could easily be changed.
  249.  
  250. The program GENBALL, in .\BALL, generates all vertex and face info
  251. for a generic ball (it doesn't generate the color info, which varies
  252. from instance to instance).  The number of bands of faces and the
  253. size of the ball are prompted for when GENBALL is run.  The output of
  254. GENBALL with 6 bands and a radius of 25 is in BALVERT0.INC, and is
  255. included in INITBALL.C, which initializes a ball for use in the
  256. animation program.  To change the size, just regenerate BALVERT0.INC
  257. by running GENBALL with bands = 6 and the desired radius.  To change
  258. the number of bands, run GENBALL with the desired number of bands and
  259. radius, and then change the Colors array in INITBALL.C to have one
  260. color entry for each face in the new ball. (The number of faces is
  261. shown as a define at the top of the output file from GENBALL.) 
  262. Additional balls may be added by changing NUM_BALLS, and by adding a
  263. new entry to each array at the top of GENBALL.C.
  264.  
  265. ----------
  266. Changed object list from an array to a linked list that is sorted
  267. in back-to-front order after each set of moves, so drawing the list
  268. in order performs proper hiding of objects.
  269.  
  270. ----------
  271. Renamed source files more meaningfully, and renamed executable XS.EXE.
  272.  
  273. ----------
  274. Added a center (0,0,0) point to each object, which is transformed into
  275. view space each time the object is transformed.  This is used for
  276. Z-sorting objects for drawing precedence purposes, and can also be
  277. used for collision detection and the like.
  278.  
  279. End entry for 12/29/91
  280. **********************************************************************
  281.  
  282.